// pages/selectFacilitator/selectFacilitator.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    enterprise_professional_facilitator_id:"",          //用户企业id
    facilitator_id:"",         //服务id
  },
  radiochange: function(e) {
    let {
      value
    } = e.detail || {}, list = this.data.list || [],self=this;
    let search_item = (list, value, cb) => {
      let data = null;
      list.forEach((v, k) => {
        if (v.facilitator_id == value) {
          cb(v)
        }
      })
    }
    search_item(list, value, function(val) {
      self.setData({
        facilitator_id: val.facilitator_id
      })
    })

  },
  async getData(id) {
    let data = await wx.$api.showEnterpriseFacilitator({
      enterprise_professional_facilitator_id: id
    })
    this.setData({
         list:data.data.data||[]
    })
    console.log('返回服务商列表',data)
  },
  async toHome(){
    let data = await wx.$api.selectFacilitator({
      enterprise_professional_facilitator_id: this.data.enterprise_professional_facilitator_id,          //企业id
      facilitator_id: this.data.facilitator_id,        //服务商id
    })
    if(data.data.code==200){
       wx.$Toast('绑定成功');
       setTimeout(()=>{
         let page = getCurrentPages()[getCurrentPages().length - 2];
         page.onLoad();
         wx.navigateBack({

         })
       },500)
    }else{
      wx.$Toast(data.data.msg)
    }
    console.log(data,'sssssssss')
    //  wx.$Toast("手机号码格式不正确");
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if(options.id){
       this.setData({
         enterprise_professional_facilitator_id:options.id,          //用户企业id
       })
       this.getData(options.id)
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  }
})